import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';  
import 'element-ui/lib/theme-chalk/icon.css';
import * as echarts from 'echarts'
import axios from 'axios'
import 'animate.css'; 
import "@/assets/css/index.css";
import 'swiper/swiper-bundle.css'
import VueScrollTo from 'vue-scrollto'
Vue.use(VueScrollTo)


import dataV from '@jiaminghi/data-view'
Vue.use(dataV)
// axios.defaults.baseURL = "/bg";

Vue.directive('debounce', {
  inserted(el, binding) {
    el.addEventListener('click', e => {
      el.classList.add('is-disabled')
      el.disabled = true
      setTimeout(() => {
        el.disabled = false
        el.classList.remove('is-disabled')
      }, 2000)//我这里设置的是2000毫秒也就是2秒
    })
  }
})
Vue.directive('copy', {
  bind: function(el, binding) {
    el.$copy = function() {
      const textarea = document.createElement('textarea');
      textarea.value = binding.value;
      document.body.appendChild(textarea);
      textarea.select();
      document.execCommand('Copy');
      document.body.removeChild(textarea);
    }
    el.addEventListener('click', el.$copy);
  },
  unbind: function(el) {
    el.removeEventListener('click', el.$copy);
  }
}); 
Vue.directive("scroll", {
  inserted: function(el, bind, vnode) {
    let scrollHeight = el.offsetHeight,
      cb_name = bind.expression, // 绑定的函数名
      cb = vnode.context[cb_name]; 
    el.addEventListener("scroll", async () => {
    		// +1防止高度不够
          if (scrollHeight + el.scrollTop + 1 >= el.firstChild.clientHeight) {
        try {
          cb && (await cb()); // 触发绑定的函数
        } catch (error) {
          console.log(error);
        }
      }
    });
  }
}); 


Vue.prototype.$axios = axios 
Vue.prototype.base_url = process.env.VUE_APP_BASE_URL 
Vue.prototype.base_api_url = process.env.VUE_APP_BASE_API_URL 
Vue.use(ElementUI); 
Vue.prototype.$echarts = echarts 
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
